Use case: Starting the GFXTIM with relative timer ¶
This use case shows how to start the relative frame counter in continuous or one-shot mode and handle frame reload events.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
GFXTIM_HandleTypeDef hgfxtim;
hgfxtim.Instance = GFXTIM;
hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RegisterCallback(&hgfxtim,
HAL_GFXTIM_RFC1_RELOAD_CB_ID,
USER_GFXTIM_RELTIM_FrmCntReloadCallback);
/* Clock generator configuration */
GFXTIM_ClockGeneratorConfigTypeDef pClockGenConfig = {
.LineClockSrc = GFXTIM_LINE_CLK_SRC_FCC_UNDERFLOW;
.FCCHwReloadSrc = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCReloadValue = 1;
.FCCClockSrc = GFXTIM_FCC_CLK_SRC_DISABLE;
.FrameClockSrc = GFXTIM_FCC_CLK_SRC_VSYNC_RISING;
.LineClockCalib = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
&pClockGeneratorConfig);
/* Configure relative timer in continuous mode */
GFXTIM_RelativeTimerConfigTypeDef pRelativeTimerConfig = {
.AutoReloadValue = 200;
.CounterMode = GFXTIM_MODE_CONTINUOUS;
.ReloadInterrupt = ENABLE;
};
HAL_GFXTIM_RelativeTimer_Config(&hgfxtim,
&pRelativeTimerConfig,
GFXTIM_RELATIVE_TIMER1);
/* Start the relative counter in continuous mode */
HAL_GFXTIM_RelativeTimer_Start(&hgfxtim,
GFXTIM_RELATIVE_TIMER1);
/* Configure relative timer in oneshot mode */
GFXTIM_RelativeTimerConfigTypeDef pRelativeTimerConfig = {
.AutoReloadValue = 200;
.CounterMode = GFXTIM_MODE_ONE_SHOT;
.ReloadInterrupt = ENABLE;
};
HAL_GFXTIM_RelativeTimer_Config(&hgfxtim,
&pRelativeTimerConfig,
GFXTIM_RELATIVE_TIMER1);
/* Start the absolute line counter in oneshot mode */
HAL_GFXTIM_RelativeTimer_Start(&hgfxtim,
GFXTIM_RELATIVE_TIMER1);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_RelativeTimer_RFC1RCallback(&hgfxtim);
/* optional */
/* Set the relative frame counter reload value */
HAL_GFXTIM_RelativeTimer_SetReload(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1,
0xFU);
/* Force reload the relative frame counter */
HAL_GFXTIM_RelativeTimer_ForceReload(&hgfxtim,
GFXTIM_RELATIVE_TIMER1);
/* Disable the relative frame counter in continuous mode */
HAL_GFXTIM_RelativeTimer_Stop(&hgfxtim);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
hal_gfxtim_handle_t hgfxtim;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RELTIM_RegisterFCntReloadCallback(&hgfxtim,
USER_GFXTIM_RELTIM_FrmCntReloadCallback);
/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val = 1;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
.clock_src = HAL_GFXTIM_CLKGEN_FRAME_VSYNC_RISING;
};
HAL_GFXTIM_CLKGEN_SetConfigFrameClock(&hgfxtim,
&p_frame_config);
/* Start the relative frame counter in continuous mode */
HAL_GFXTIM_RELTIM_StartContinuous(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1,
200U,
HAL_GFXTIM_RELTIM_COUNT_IT);
/* Start the relative frame counter in one shot mode */
HAL_GFXTIM_RELTIM_StartOneShot(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1,
200U,
HAL_GFXTIM_RELTIM_COUNT_IT);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_RELTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_RELTIM_FCntReloadCallback(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1);
/* optional */
/* Set the relative frame counter reload value */
HAL_GFXTIM_RELTIM_SetReloadValue(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1,
0xFU);
/* Force reload the relative frame counter */
HAL_GFXTIM_RELTIM_ForceReload(&hgfxtim,
GFXTIM_RELATIVE_TIMER1);
/* Stop the relative frame counter in continuous mode */
HAL_GFXTIM_RELTIM_StopContinuous(&hgfxtim,
HAL_GFXTIM_RELTIM_COUNTER_1);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
|
Key changes ¶
In HAL2, relative timer configuration is merged with the start API, with separate entry points for continuous and one-shot modes.
HAL2 provides dedicated IRQ handling and callback registration for relative timer events.

